import axios from '../utils/axios';

/**
 * 编辑数据
 * @author LXBsmile
 * @date 2019-12-09
 * @param {Object} post 数据对象
 * @returns {Promise}
 */
export function editData(post) {
  return axios
    .post("fes/device/dataareaNameEdit", post)
    .then(res => {
      if (res.code === 1) return res.data;
      else throw res.msg;
    })
}

/**
 * 删除数据
 * @author LXBsmile
 * @date 2019-12-09
 * @param {Number} id
 * @returns {Promise}
 */
export function delData(id) {
  return axios.delete(`fes/device/dataareaNameRemove?pkid=${id}`).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

/**
 * 删除数据模版
 * @author LXBsmile
 * @date 2019-12-11
 * @param {Number} id 模版id
 * @returns {Promise}
 */
export function delDataTmp(id) {
  return axios.delete(`fes/device/data/acqTemplate/delete?pkid=${id}`).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function getDevs(clientId, substationId) {
  const params = {
    clientId,
    substationId
  }
  return axios.get('/fes/fesDevice/droplist', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}
